package leecode;

import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 *
 * @author qingyan 2021-12-20
 */
public class Question58 {


    public static int lengthOfLastWord(String s) {
        char[] chars = s.toCharArray();
        int len = chars.length;
        for (int i = len - 1;i >= 0; i--) {
            if (chars[i] == ' ') {
                continue;
            }
            int j = i;
            // " moon"
            while (j > 0 && chars[--j] != ' ') {
                j = j == 0 ? -1 : j;
            }
            return i - j;
        }
        return 0;
    }

    public static void main(String[] args) {
        System.out.println(lengthOfLastWord(" aa"));
    }
}
